package com.sand.controller;

import com.sand.entity.inventory.SelectInventory;
import com.sand.entity.inventory.inventory;
import com.sand.result.PageResult;
import com.sand.result.ResponseResult;
import com.sand.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;


    /**
     * 添加商品时新增库存
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody inventory inventory){
        Integer i =  inventoryService.add(inventory);
        return new ResponseResult<Integer>().ok(i);
    }

    /**
     * 完成采购新增库存
     */
    @PostMapping("/addlist")
    public ResponseResult<Integer> addlist(@RequestBody Integer purchaseid){
        Integer i =  inventoryService.addlist(purchaseid);
        return new ResponseResult<Integer>().ok(i);
    }


    /**
     * 根据合同扣减库存
     */
    @PostMapping("/subtract")
    public ResponseResult<Integer> subtract(@RequestBody Integer contractid){
        Integer i = inventoryService.subtract(contractid);
        return new ResponseResult<Integer>().ok(i);
    }



    /**
     * 查询某个商品拼的库存
     */
    @PostMapping("/get")
    public ResponseResult<inventory> get(@RequestBody Integer shoppingid){
        inventory inventory = inventoryService.get(shoppingid);
        return new ResponseResult<inventory>().ok(inventory);
    }



    /**
     * 根据条件查询库存查询库存
     */
    @PostMapping("/select")
    public PageResult<List<inventory>> getList(@RequestBody SelectInventory selectInventory){

         List<inventory> list =  inventoryService.getList(selectInventory);

         return new PageResult<List<inventory>>().ok(list, list.size());
    }



}
